package com.fuyao.cloud.personnel.problem.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.data.mybatis.SpliceQueryWrapper;
import com.fuyao.cloud.common.excel.annotation.RequestExcel;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.personnel.api.entity.Supervised;
import com.fuyao.cloud.personnel.api.vo.SupervisedSearchVO;
import com.fuyao.cloud.personnel.api.vo.excel.SupervisedExcelVO;
import com.fuyao.cloud.personnel.problem.service.SupervisedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监督情况表
 *
 * @author hyc
 * @date 2022-05-20 10:52:19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/supervised" )
@Api(value = "supervised", tags = "监督情况表管理")
public class SupervisedController {

    private final  SupervisedService supervisedService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param supervised 监督情况表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('supervised_view')" )
    public R getFySupervisedPage(Page page, SupervisedSearchVO supervised) {
        return R.ok(supervisedService.page(page, SpliceQueryWrapper.spliceSearchCondition(supervised)));
    }


    /**
     * 通过id查询监督情况表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('supervised_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(supervisedService.getById(id));
    }

    /**
     * 新增监督情况表
     * @param fySupervised 监督情况表
     * @return R
     */
    @ApiOperation(value = "新增监督情况表", notes = "新增监督情况表")
    @SysLog("新增监督情况表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('supervised_add')" )
    public R save(@RequestBody Supervised fySupervised) {
        return R.ok(supervisedService.save(fySupervised));
    }

    /**
     * 修改监督情况表
     * @param fySupervised 监督情况表
     * @return R
     */
    @ApiOperation(value = "修改监督情况表", notes = "修改监督情况表")
    @SysLog("修改监督情况表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('supervised_edit')" )
    public R updateById(@RequestBody Supervised fySupervised) {
        return R.ok(supervisedService.updateById(fySupervised));
    }

    /**
     * 通过id删除监督情况表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除监督情况表", notes = "通过id删除监督情况表")
    @SysLog("通过id删除监督情况表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('supervised_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(supervisedService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param supervised 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @PostMapping("/export")
    @PreAuthorize("@pms.hasPermission('supervised_export')" )
    public List<Supervised> export(Supervised supervised) {
        return supervisedService.list(Wrappers.query(supervised));
    }

    /**
     * 导入
     * @return R
     */
    @PostMapping("/import")
    @PreAuthorize("@pms.hasPermission('supervised_export')")
    public R importSupervised(@RequestExcel List<SupervisedExcelVO> excelVOList, BindingResult bindingResult) {
        return supervisedService.importSupervised(excelVOList, bindingResult);
    }

//    @ResponseExcel
//    @GetMapping("/export")
//    @PreAuthorize("@pms.hasPermission('supervised_export')" )
//    public List<Supervised> export(Supervised supervised, @Head @RequestBody List<HeadProperty> headProperties) {
//        return supervisedService.list(Wrappers.query(supervised));
//    }
}
